|
|
|
|
|
|
|
In order to make changes to a record, a copy of the current record is placed into the copy buffer so that data can be changed. After the user changes the data, you would need to execute the Update method. As with the AddNew method, the changes take effect only when the Update method is executed (see Listing 10.6). |
|
|
|
|
|
|
|
|
LISTING 10.6. ADOEX6.TXTADDING THEEditROUTINE TO THE APPLICATION. |
|
|
|
 |
|
|
|
|
1: Private Sub cmdUpdate_Click()
2: MyDyn!Title = This is my Book
3: MyDyn.Update
4: Call SetFields
5: End Sub |
|
|
|
|
|
|
|
|
The Update method used with the AddNew and Edit methods writes the data from the copy buffer to the recordset. In the case of AddNew, Update also creates a blank record in the recordset to which the data is written. |
|
|
|
|
|
|
|
|
Caution When editing a record and updating it, you should never try to update the primary key fields in the data. This usually causes an error to occur. |
|
|
|
|
|
|
|
|
|
Finally, if you need to delete a record, use the Delete method (see Listing 10.7). This method removes the record from the recordset and sets the record pointer to a null value. |
|
|
|
|
|
|
|
|
LISTING 10.7. DAOEX7.TXTADDING THEDeletePROCESS TO THE FORM. |
|
|
|
 |
|
|
|
|
1: Private Sub cmdDelete_Click()
2: MyDyn.Delete
3: MsgBox Record has been deleted, vbInformation, App.Title
4: Call cmdNext_Click
5: End Sub |
|
|
|
|
|
|
|
|
As you can see, after the Delete method is executed, the cmdNext click routine is called to move the current record pointer to the next valid record in the recordset. If this wasn't done, an error would occur. |
|
|
|
|
|
|
|
|
To see how all this works, add three more command buttons to the form, as shown in Figure 10.11. Then, add the code for each of these actions. Now run the application again and try each action to see how it works. |
|
|
|
|
|